import Vue 			from 'vue'
import util 		from '../../util'
import axios 		from 'axios'
import { Toast } 	from 'vant';
Vue.use(Toast);

export default {
	name: 'goRealName2',
	data(){
		return {
			place:'',			//地区
			name:'',			//姓名
			IDtype:'',			//证件类型
			IDCode:'',			//证件号码
			error1:'',
			error2:'',
			error3:'',
			error4:'',
			loading:false,		//是否提交中
		}
	},
	methods:{
		blur(){
			window.scrollTo(0, 0);
		},
		upload(){
			//提交
			this.updateDialog();
			return
			this.checkout().then(() => {
				this.loading = true;
				let params = {
					token:this.token || window.token || util.getToken(),
					kyc_type:2,						//1:国内   2:其他地区
					name:this.name,					//姓名
					id_no:this.IDCode,				//证件号码
					kyc_area:this.place,			//地区   china  america
					kyc_certificate:this.IDtype,	//证件类型
				}
				util.fetch(`${util.ajaxUrl}/user/verified`,params).then(res => {
					if(res.retCode === 0){
						Toast(this.$t('goRealName-key10'));
						setTimeout(()=>{
							util.navigateBack(-2,this,1)
							// this.$router.go(-2);
							this.loading = false;
						},1500)
					}else{
						Toast(res.retMsg || this.$t('noError'))
						setTimeout(()=>{
							this.loading = false;
						},1500)
					}
				}).catch(error => {
					this.loading = false;
					console.log(error)
				})
			}).catch(error => {

			})
		},
		checkout(){
			return new Promise((resolve,reject) => {
				if(this.place && this.name && this.IDtype && this.IDCode){
					this.error1 = '';
					this.error2 = '';
					this.error3 = '';
					this.error4 = '';
					resolve()
				}else{
					this.error1 = this.place?'':this.$t('goRealName-key13');
					this.error2 = this.name?'':this.$t('goRealName-key11');
					this.error3 = this.IDtype?'':this.$t('goRealName-key14');
					this.error4 = this.IDCode?'':this.$t('goRealName-key15');
					reject('')
				}
			})
		},
		goBack(special){
			util.navigateBack(-1,this,special)
			// this.$router.go(-1)
		}
	},
	created() {
		util.waitSDKReady().then(token => {
			this.token = token;
		}).catch((e) => {
			console.log('获取token失败')
		})
		setTimeout(() => {
			//退出登录的时候native调用H5方法清除token缓存
			util.registerHandler('loginOutDeleteToken',res => {
				localStorage.removeItem('token');
			})
			util.callHandler('setStatusBarStyle',{
				style:'dark'
			})
		},300)
		// this.init();
    }
}